﻿@using Coevery.Entities.Settings
@using Orchard.Utility.Extensions
@model Coevery.Entities.ViewModels.EditPartFieldViewModel
@{
    var fieldSettingsPrefix = Model.FieldDefinition.Name + "Settings";
    var settings = Model.Settings.GetModel<FieldSettings>(fieldSettingsPrefix);
}

<header id="page-title">
    <h1 class="pull-left">@T("Field Detail") <span>Edit field information</span></h1>
</header>

<section id="main-content" style="margin-top: 47px">
    <div id="page-actions" class="clearfix">
        <btn-actions>
            <button type="button" class="btn btn-small" data-ng-click="exit()">Back</button>
            <button type="button" class="btn btn-small btn-primary" data-indi-click="save()">Save</button>
            <button class="btn btn-small btn-primary" data-indi-click="saveAndBack()">Save & Back</button>
        </btn-actions>
    </div>
    <div class="row-fluid">
        <div class="span12">
            <div class="form-horizontal no-border">
                @using (Html.BeginFormAntiForgeryPost(Html.ViewContext.HttpContext.Request.Url.PathAndQuery, FormMethod.Post,
                                              new { @class = "form-horizontal no-border edit-mode", @name = "myForm", @ng_submit = "save()", @id = "field-info-form" }))
                {
                    @Html.ValidationSummary()
                    <fieldset>
                        <legend>General Information</legend>
                        <section class="data-row control-group">
                            <label class="control-label" for="DisplayName">@T("Field Label")</label>
                            <div class="controls errortips">
                                @Html.TextBoxFor(m => m.DisplayName, new { @class = "span12", autofocus = "autofocus",required=""})
                            </div>
                        </section>
                        <section class="data-row control-group">
                            <label class="control-label" for="Name">@T("Field Name")</label>
                            <div class="controls">
                                @Html.TextBoxFor(m => m.Name, new { @class = "span12", disabled = "disabled" })
                                @Html.HiddenFor(m => m.Name)
                            </div>
                        </section>
                        <section class="data-row control-group">
                            <label class="control-label" for="FieldTypeName">@T("Field Type")</label>
                            <div class="controls">
                                @Html.TextBoxFor(m => m.FieldDefinition.Name, new { @class = "span12", disabled = "disabled" })
                            </div>
                        </section>
                        <section class="data-row control-group">
                            <label class="control-label">
                                Options
                            </label>
                            <div class="controls">
                                <label class="checkbox">
                                    @if (settings.IsSystemField) {
                                        @Html.Hidden(fieldSettingsPrefix + ".Required", settings.Required)
                                        @Html.CheckBox(fieldSettingsPrefix + ".Required", settings.Required, new {disabled = "disabled"})
                                    }
                                    else {
                                        @Html.CheckBox(fieldSettingsPrefix + ".Required", settings.Required)
                                    }
                                    @T("Required")
                                </label>
                                <label class="checkbox">
                                    @if (settings.IsSystemField) {
                                        @Html.Hidden(fieldSettingsPrefix + ".AlwaysInLayout", settings.AlwaysInLayout)
                                        @Html.CheckBox(fieldSettingsPrefix + ".AlwaysInLayout", settings.AlwaysInLayout, new { disabled = "disabled" })
                                    }
                                    else {
                                        @Html.CheckBox(fieldSettingsPrefix + ".AlwaysInLayout", settings.AlwaysInLayout);
                                    }
                                    @T("Always In Layout")
                                </label>
                                <label class="checkbox">
                                    @if (settings.IsSystemField) {
                                        @Html.Hidden(fieldSettingsPrefix + ".IsAudit", settings.IsAudit);
                                        @Html.CheckBox(fieldSettingsPrefix + ".IsAudit", settings.IsAudit, new { disabled = "disabled" });
                                    }
                                    else {
                                        @Html.CheckBox(fieldSettingsPrefix + ".IsAudit", settings.IsAudit);
                                    }
                                    @T("IsAudit")
                                </label>
                            </div>
                        </section>
                        <section class="data-row control-group">
                            <label class="control-label" for="helpText">
                                @T("Help Text")
                            </label>
                            <div class="controls">
                                @Html.TextArea(fieldSettingsPrefix + ".HelpText", settings.HelpText, new { @class = "span12" })
                            </div>
                        </section>
                    </fieldset>
                    <fieldset>
                        <legend>Field Information</legend>                      
                        @{Html.RenderTemplates(Model.Templates);}
                    </fieldset>
                    @Html.Hidden(fieldSettingsPrefix + ".IsSystemField", Model.Settings[fieldSettingsPrefix + ".IsSystemField"])
                }
            </div>
        </div>
    </div>
</section>
